package dp.ua.epic.webapp;

import dp.ua.epic.resource.ExternalResourceLoader;
import dp.ua.epic.resource.LocaleDetector;
import dp.ua.epic.pages.Start;
import java.util.List;
import java.util.Locale;
import org.apache.wicket.Request;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.Response;
import org.apache.wicket.Session;
import org.apache.wicket.application.IComponentInstantiationListener;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.WebResponse;
import org.wicketstuff.annotation.scan.AnnotatedMountScanner;

/**
 *
 * @author Artem Kozlov
 */
public class EpicApplication extends WebApplication {

    public static List<Locale> aviableLocales;
    public static final String LOCALIZATION_CONFIG_FILE = "/dp/ua/epic/directories.properties";

    public EpicApplication() {
    }

    @Override
    protected void init() {
        super.init();
        addComponentInstantiationListener(getSpringComponentInjector(this));
        new AnnotatedMountScanner().scanPackage("dp.ua.epic.pages").mount(this);
        getResourceSettings().addStringResourceLoader(new ExternalResourceLoader("Fates"));
        aviableLocales = LocaleDetector.getAviableLocales(LOCALIZATION_CONFIG_FILE);
    }

    @Override
    public Class<Start> getHomePage() {
        return Start.class;
    }

    @Override
    public Session newSession(Request request, Response response) {
        return new EpicSession(request);
    }

    @Override
    public RequestCycle newRequestCycle(Request request, Response response) {
        return new EpicRequestCycle(this, (WebRequest) request, (WebResponse) response);
    }

    protected IComponentInstantiationListener getSpringComponentInjector(WebApplication application) {
        return new SpringComponentInjector(application);
    }
}
